home *** CD-ROM | disk | FTP | other *** search
- /* -*-c-*- */
-
- /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
-
- This file is part of GNU CC.
-
- GNU CC is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- /* As a special exception, if you link this library with files
- compiled with GCC to produce an executable, this does not cause
- the resulting executable to be covered by the GNU General Public License.
- This exception does not however invalidate any other reasons why
- the executable file might be covered by the GNU General Public License. */
-
- /*
- * $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/objc-core.c,v 1.14
- * 1992/01/03 02:55:03 dennisg Exp dennisg $ $Author: dglattin $ $Date:
- * 1992/01/03 02:55:03 $ $Log: record-inline.h,v $
- * Revision 1.3 1992/08/18 04:46:58 dglattin
- * Saving a working version before release.
- *
- * Revision 1.2 1992/04/13 11:43:08 dennisg
- * Check in after array version of run-time works.
- * Expect more changes as hash version and other changes are made.
- *
- * Revision 1.1 1992/02/25 11:12:45 dennisg
- * Initial revision
- *
- */
-
-
- #ifndef _record_inline_INCLUDE_GNU
- #define _record_inline_INCLUDE_GNU
-
- #include <assert.h>
- #include <stdlib.h>
- #include <sys/types.h>
-
- /* Structure to hold records. */
- typedef struct _Record {
- u_int capacity,
- numEntries;
- void* (*records)[];
- } Record, *Record_t;
-
-
- /* Allocate, initialize and return a new record structure. */
- static inline Record_t
- record_new (void) {
-
- Record_t newRecord;
-
-
- newRecord = calloc (1, sizeof (Record));
- assert(newRecord);
- newRecord->capacity = 8;
- newRecord->records = calloc (newRecord->capacity, sizeof (void*));
- assert(newRecord->records);
-
- return newRecord;
- }
-
-
- /* Delete the record. */
- static inline void
- record_delete (Record_t record) {
-
- free (record->records);
- free (record);
- }
-
-
- /* Return the number of entries in the reord. */
- static inline u_int
- record_entries (Record_t record) {
-
- return record->numEntries;
- }
-
-
- /* return the capacity of the record. */
- static inline u_int
- record_capacity (Record_t record) {
-
-
- return record->capacity;
- }
-
-
- /* Store an entry at the specified record location. */
- static inline void
- record_store_at (u_int i, void* value, Record_t record) {
-
-
- assert(i);
- assert(i <= record_entries (record));
-
- (*record->records)[ i ] = value;
- }
-
-
- /* Make a record entry. Expand the record's size if full. */
- static inline void
- record_store (void* value, Record_t record) {
-
-
- ++record->numEntries;
- if(record_entries (record) == record_capacity (record)) {
- record->capacity *= 2;
- record->records =
- realloc (record->records, (record_capacity (record) * sizeof (void*)));
- }
- record_store_at (record_entries (record), value, record);
- }
-
-
- /* get a value from the record. */
- static inline void*
- record_get (u_int i, Record_t record) {
-
-
- assert( i );
- assert( i <= record_entries (record));
- return (*record->records)[ i ];
- }
-
- #endif
-
-